package com.zto.sch.base.exception;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2021-05-28 16:56
 **/
@Slf4j
public class ExceptioinTest {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        ExceptioinTest exceptioinTest = new ExceptioinTest();
        Class clz = exceptioinTest.getClass();
        Method addMethod = clz.getDeclaredMethod("divde", int.class, int.class);
        boolean debugEnabled = log.isDebugEnabled();

        try {

            System.out.println(addMethod.invoke(new ExceptioinTest(), 1, 0));
        } catch (Exception e) {
            log.error("获取用户[{}]的用户信息时出错,异常信息:[{}]", 1, ExceptionUtils.getFullStackTrace(e));
            log.error("获取用户[{}]的用户信息时出错,", 1, e);

        }
    }


    private double divde(int x, int y) {
        if (y == 0) {
            throw new MyException("除数不能为0");
        }
        return 1.0 * x / y;
    }
}
